import { Injectable } from '@angular/core';
import toastr from 'toastr';

@Injectable({
	providedIn: 'root',
})
export class ToasterService {
	private t = toastr;
	option = {};
	constructor() {

		let oldError=this.t.error,t=this.t;
		// console.log('oldError--:',oldError)
		t['error']=function(){
			if((''+arguments[0]).trim()!='401' && (''+arguments[1]).trim()!='401'){
				return oldError.apply(t,arguments)
			}
		}
		window['$angularToast']=this;
	}
	warn(text: string, title?: string) {
		if((''+arguments[0]).trim()=='401' || (''+arguments[1]).trim()=='401'){
			return false;
		}
		this.t.error(text, title, { timeOut: 3000, ...this.option });
	}
	info(text: string, title?: string) {
		if((''+arguments[0]).trim()=='401' || (''+arguments[1]).trim()=='401'){
			return false;
		}
		this.t.info(text, title, { timeOut: 1000, ...this.option });
	}
	success(text: string, title?: string) {
		if((''+arguments[0]).trim()=='401' || (''+arguments[1]).trim()=='401'){
			return false;
		}
		this.t.success(text, title, { timeOut: 2000, ...this.option });
	}
}
